'use strict';
module.exports = app => {
  const { STRING, INTEGER } = app.Sequelize;
    const model = app.model.define(
      'user',
      {
          id: {type: INTEGER, primaryKey: true, autoIncrement: true},
          username: STRING(255),
          password: STRING(255),
          nickname: STRING(255),
          image: STRING(255),
          phone: STRING(255),
          status: INTEGER(11),
          type: INTEGER(11),
          role_id: INTEGER(11),
      },
      {
          tableName: 'user',
          timestamps: true, // 启用时间戳(createdAt, updatedAt)
          updatedAt: 'updated_time', // 不想要 updatedAt
          createdAt: 'create_time', // 想要  createdAt 但是希望名称叫做 created_at
      }
    );
    // 关联关系
    model.associate = function() {
        // 一对一post
        app.model.User.hasMany(app.model.Post, { foreignKey: 'user_id', sourceKey: 'id' });
        app.model.User.hasMany(app.model.Comment, { foreignKey: 'user_id', sourceKey: 'id' });
        app.model.User.hasMany(app.model.Like, { foreignKey: 'user_id', sourceKey: 'id' });
        app.model.User.hasMany(app.model.Collect, { foreignKey: 'user_id', sourceKey: 'id' });
        app.model.User.hasMany(app.model.Answer, { foreignKey: 'user_id', sourceKey: 'id' });
    }
    return model
};
